package com.cy.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * @DATE: 2021/3/18 9:24
 * @Author: LuckyH
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@interface Entity{
    String value() default "";
}


@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD,ElementType.METHOD})
@interface ID{
    String value() default "";
}


@Entity("t user")
class User{
    @ID("uid")
    private Integer id;
}

public class AnnotationTest {

    public static void main(String[] args) throws Exception, NoSuchFieldException {
        Class<?> clazz = Class.forName("com.cy.annotation.User");

        String value = User.class.getAnnotation(Entity.class).value();
        System.out.println(value);

        Entity annotation = clazz.getAnnotation(Entity.class);

        System.out.println(annotation.value());

        String value1 = User.class.getDeclaredField("id").getAnnotation(ID.class).value();
        System.out.println(value1);
        ID id = clazz.getDeclaredField("id").getAnnotation(ID.class);
        System.out.println(id.value());

    }
}













